package com.example.campusproject.slice;

import com.example.campusproject.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;

import java.util.Arrays;

public class XSZNAbilitySlice extends AbilitySlice {
    private String[] titles = new String[] { "整理新装", "抵达目的地", "入校第一站", "我是一个兵",
            "生活万花筒", "结交新朋友", "勤练有补助", "学长学姐寄语" };
    private Text[] texts=new Text[titles.length];
    private DirectionalLayout dl;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        this.setUIContent(ResourceTable.Layout_ability_xszn);
        dl= (DirectionalLayout) this.findComponentById(ResourceTable.Id_dl_xszn);
        dl.removeAllComponents();
        for (int i = 0; i < texts.length; i++) {
            texts[i]=new Text(this);
            texts[i].setText(titles[i]);
            texts[i].setTextColor(Color.BLACK);
            texts[i].setTextSize(80);
            texts[i].setTextAlignment(TextAlignment.CENTER);
            DirectionalLayout.LayoutConfig lc=new DirectionalLayout.LayoutConfig(
                    ComponentContainer.LayoutConfig.MATCH_CONTENT,
                    DirectionalLayout.LayoutConfig.MATCH_CONTENT
            );
            texts[i].setLayoutConfig(lc);
            texts[i].setTag(i);
            texts[i].setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    intent.setParam("index",(int)((Text)component).getTag());
                    present(new XSZNDetailsAbilitySlice(),intent);
                }
            });
            dl.addComponent(texts[i]);
        }
    }
}
